package com.one.group.admin.listener;

import com.one.group.admin.service.impl.SpBillServiceImpl;
import com.one.group.model.dto.SpBillAddTestDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class SpbillListener {
    @Autowired
    private SpBillServiceImpl spBillServiceImpl;
    /**
     * 监听添加账单消息
     * @param spBillAddTestDto 账单信息
     */
    @RabbitListener(bindings = @QueueBinding(value = @Queue(name = "direct.queue1"),
            exchange = @Exchange(name = "gxa.direct"), key = {"addBill"}))
    public void listenerDirectQueue1Message(SpBillAddTestDto spBillAddTestDto) {
        log.info("监听到消息：{}", spBillAddTestDto);
        try{
            if(!spBillServiceImpl.BillAdd(spBillAddTestDto)){
                log.info("添加账单失败");
            }
            else log.info("添加账单成功");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
